package com.example.rlw.mvpplugintest.utils;

import android.content.Context;
import android.content.Intent;

import com.example.rlw.mvpplugintest.login.LoginActivity;
import com.example.rlw.mvpplugintest.prompt.ErrorCallback;
import com.example.rlw.mvpplugintest.prompt.TimeoutCallback;
import com.kingja.loadsir.core.LoadService;

/**
 * Created by rlw on 2018/10/17.
 */

public class ErrorCodeUtills {
    /**
     * 对通用问题的统一拦截处理
     * eg: code 101 token失效，登出App
     *
     * @param code
     */
    public static void disposeEorCode(int code, String message, Context context, LoadService loadService) {
        switch (code) {
            case -1:
                loadService.showCallback(ErrorCallback.class);
                break;
            case 101:
                //退回到登录页面
                Intent intent = new Intent();
                intent.setClass(context, LoginActivity.class);
                context.startActivity(intent);
                break;
            case 1004:
                loadService.showCallback(TimeoutCallback.class);
                break;
            case 1003:
                loadService.showCallback(TimeoutCallback.class);
                break;
            default:
                loadService.showCallback(ErrorCallback.class);
                break;
        }
        AtomsUtils.makeText(context, message);
    }
}
